package de.velvettear.squirrel.util;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import de.velvettear.squirrel.R;
import de.velvettear.squirrel.gui.ScanFrame;
import de.velvettear.squirrel.gui.Splash;
import de.velvettear.squirrel.kernel.Statics;

public class NotificationHelper {

	private static NotificationManager manager;
	
	public static void setNotification(Context context, int notificationID) {		
		manager = (NotificationManager) context.getSystemService(Service.NOTIFICATION_SERVICE);
				
		String title = "";
		String text = "";
		int iconID = R.drawable.icon_app;
						
		NotificationCompat.Builder mBuilder =
				new NotificationCompat.Builder(context)
		.setSmallIcon(iconID)
		.setContentTitle(title)
		.setContentText(text)
		.setOngoing(true)
		.setPriority(NotificationCompat.PRIORITY_MAX);
		
		Intent notificationIntent = new Intent(context, Splash.class);
				
		if (notificationID == Statics.NOTIFICATION_ID_NFC) {
			title = "Squirrel NFC";
			text = "Tap to scan ...";
			iconID = R.drawable.icon_app;
			
			notificationIntent = new Intent(context, ScanFrame.class);
			notificationIntent.setFlags(notificationIntent.getFlags() | Intent.FLAG_ACTIVITY_NO_HISTORY);
		}
		
		PendingIntent pendingIntent = PendingIntent.getActivity(
		        context,
		        0,
		        notificationIntent,
		        PendingIntent.FLAG_UPDATE_CURRENT
		);
		
		mBuilder.setContentIntent(pendingIntent);
		
		manager.notify(Statics.NOTIFICATION_ID_LED, mBuilder.build());	
	}
	
	public static void removeNotification(Context context, int notificationID) {
		if (manager == null) {
			manager = (NotificationManager) context.getSystemService(Service.NOTIFICATION_SERVICE);
		}
		
		manager.cancel(notificationID);
	}
	
}
